package com.domain.controller;

import com.domain.common.Comments;
import com.domain.common.Result;
import com.domain.service.BusinessCardService;
import com.domain.utils.JwtUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 个人名片
 */
@Controller
@RequestMapping("/businesscard")
public class BusinessCardController {

    @Autowired
    private BusinessCardService businessCardService;

    /**
     * 获取个人名片（他人）
     *
     * @param userToken 用户token
     * @param userId    用户id
     * @param chUsersId 被点击用户得id
     * @return
     */
    @RequestMapping(value = "/getUsersCards", method = RequestMethod.POST)
    @ResponseBody
    public Result getUsersCards(String userToken, String userId, String chUsersId) {
        try {
            //判断用户是否登录
            if (!JwtUtils.veryfiy(userToken)) {
                return Result.publicResult(Comments.NEED_LOGIN, "请登录");
            }
            return businessCardService.getUsersCards(userId, chUsersId);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.fail("系统错误");
        }
    }

    /**
     * 请求加好友
     *
     * @param userToken 用户token
     * @param userId    用户 id
     * @param friendId  好友id
     * @param groupId   群id
     * @return
     */
    @RequestMapping(value = "/addFriends", method = RequestMethod.POST)
    @ResponseBody
    public Result addFriends(String userToken, String userId, String friendId, String groupId, String type) {
        try {
            //判断用户是否登录
            if (!JwtUtils.veryfiy(userToken)) {
                return Result.publicResult(Comments.NEED_LOGIN, "请登录");
            }
            return businessCardService.addFriends(userId, friendId, groupId, type);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.fail("系统错误");
        }
    }


}